package com.hdax.dm.feign.fallback;

import com.hdax.dm.entity.base.Image;
import com.hdax.dm.feign.ImageFeign;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class ImageFallbackFactory implements FallbackFactory<ImageFeign> {


    //当远程调用失败的时候，下面方法会执行
    @Override
    public ImageFeign create(Throwable cause) {
        return new ImageFeign() {
            //内部接口实现
            @Override
            public Image image(Long targetId, Long type, Long category) {

                Image image=new Image();
                image.setImgUrl("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fqimg.hxnews.com%2F2019%2F0401%2F1554082435788.jpeg&refer=http%3A%2F%2Fqimg.hxnews.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1666751733&t=a2c51c41e8034bc03bc3f3ebab10cd3d");
                System.out.println("==============================");
                System.err.println("远程调用失败");
                System.out.println("==============================");
                return image;
            }
        };
    }
}
